# set(CMAKE_C_COMPILER "C:/mingw64/bin/gcc.exe")
# set(CMAKE_CXX_COMPILER "C:/mingw64/bin/g++.exe")
# set(CMAKE_C_COMPILER "D:/msys64/mingw64/bin/gcc.exe")
# set(CMAKE_CXX_COMPILER "D:/msys64/mingw64/bin/g++.exe")

set(TARGET main)

cmake_minimum_required(VERSION 3.10)
project(${TARGET})

# 设置编译选项
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g")

# 查找OpenCV包
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

# 启用 Qt 的 MOC/UIC/RCC 自动处理
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 查找 Qt 库（需指定组件，如 Widgets、Core）
find_package(Qt6 COMPONENTS Core Gui Widgets REQUIRED)

# 查找动态库路径
message(STATUS "binary dir:" ${CMAKE_BINARY_DIR})
message(STATUS "source dir:" ${CMAKE_SOURCE_DIR})

# 添加可执行文件
add_executable(${TARGET}
    main.cpp
    MainWindow.cpp
    MainWindow.h
    mainwindow.ui  # 直接包含 UI 文件
)

if(${LIB_TYPE} EQUAL SHARED)
    target_compile_definitions(${TARGET} PRIVATE MYLIB_DYNAMIC_IMPORT) # 引用动态链接库时需要
endif()

if(${LIB_TYPE} STREQUAL SHARED OR ${LIB_TYPE} STREQUAL STATIC)
    find_library(MY_LIB_FILE my_lib PATHS ${CMAKE_BINARY_DIR}/lib)
    if(MY_LIB_FILE)
        message(STATUS "Found my library: ${MY_LIB_FILE}")
    else()
        message(STATUS "my library not found, using default lib: my_lib") # my_lib为dll工程的TARGET
        set(MY_LIB_FILE my_lib)
    endif()
else()
    set(MY_LIB_FILE my_lib)

    # # 查找并加载对象库配置
    # add_library(third_party_objects OBJECT IMPORTED)
    # set_target_properties(third_party_objects PROPERTIES
    #     IMPORTED_OBJECTS "${CMAKE_BINARY_DIR}/dll_lib/CMakeFiles/my_lib.dir/my_lib.cpp.obj"
    # )

endif()

# 链接 opencv Qt 库等
target_link_libraries(${TARGET} PUBLIC ${OpenCV_LIBS} Qt6::Widgets ${MY_LIB_FILE})
